﻿using Newtonsoft.Json;
using System.ComponentModel;
using System.Windows;
using VisionDesigner.ImageBinary;
using VM.Common.Enums;
using VM.Common.Helper;

namespace Plugin.Binary
{
    [JsonObject(MemberSerialization.OptOut)]
    public class ParamModel : NotifyPropertyBase
    {
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {

            { "硬阈值化", "HardThreshold" },
            { "均值二值化", "MeanThreshold" },
            { "高斯二值化", " GaussianThreshold" },
            { "OTSU", "OTSU" },
            { "Sauvola", "Sauvola" },


        };



        // 阈值方式
        private List<string> _ThresholdTypeArray = EnumHelper.GetEnumDescriptions<ThresholdTypes>();
        [Newtonsoft.Json.JsonIgnore]
        public List<string> ThresholdTypeArray
        {
            get { return _ThresholdTypeArray; }
            set { Set(ref _ThresholdTypeArray, value); }
        }
        //滑动快最大最小
        private int _ThresholdLow = 100;
        public int ThresholdLow
        {
            get { return _ThresholdLow; }
            set
            {
                Set(ref _ThresholdLow, value);


            }


        }
        private int _ThresholdHigh = 150;
        public int ThresholdHigh
        {
            get { return _ThresholdHigh; }
            set
            {
                Set(ref _ThresholdHigh, value);

            }

        }
        private string _ThresholdType = EnumHelper.GetEnumDescription(ThresholdTypes.HardThreshold);
        public string ThresholdType
        {
            get { return _ThresholdType; }
            set
            {
                Set(ref _ThresholdType, value);
                UpdateThresholdVisible();
            }
        }

        private Visibility _LowThresholdVisible = Visibility.Visible;
        public Visibility LowThresholdVisible
        {
            get { return _LowThresholdVisible; }
            set { Set(ref _LowThresholdVisible, value); }
        }

        private Visibility _HightThresholdVisible = Visibility.Visible;
        public Visibility HightThresholdVisible
        {
            get { return _HightThresholdVisible; }
            set { Set(ref _HightThresholdVisible, value); }
        }







        //二值化
        public void Binaryupdata(CImageBinaryTool cImagebinary)
        {//阈值方式
            cImagebinary.SetRunParam("BinaryType", ParamMap[ThresholdType]);
            //值

            cImagebinary.SetRunParam("LowThreshold", ThresholdLow.ToString());
            cImagebinary.SetRunParam("HighThreshold", ThresholdHigh.ToString());

        }



        private void UpdateThresholdVisible()
        {
            switch (ThresholdType)
            {
                case "硬阈值化":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;

                    break;
                case "均值二值化":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;

                    break;
                case "双阈值":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;

                    break;
                case "高斯二值化":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;

                    break;
                case "OTSU":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;

                    break;
                case "Sauvola":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;

                    break;
                default:
                    break;
            }
        }


    }


    /// <summary>
    /// 输出图像
    /// </summary>

    public enum OutImageTypes
    {
        原图,
        二值化图像,

    }

    /// <summary>
    /// 阈值方式
    /// </summary>

    public enum ThresholdTypes
    {
        [Description("硬阈值化")]
        HardThreshold,

        [Description("均值二值化")]
        MeanThreshold,

        [Description("高斯二值化")]
        GaussianThreshold,

        [Description("OTSU")]
        OTSU,

        [Description("Sauvola二值化")]
        Sauvola,


    }


}
